home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / ui / UIButton.as < prev   
Encoding:
Text File  |  2011-10-17  |  1.3 KB  |  57 lines

  1. package ui
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.Event;
  5.    import flash.events.MouseEvent;
  6.    
  7.    [Embed(source="/_assets/assets.swf", symbol="ui.UIButton")]
  8.    public class UIButton extends MovieClip
  9.    {
  10.        
  11.       
  12.       public var _tHolder:MovieClip;
  13.       
  14.       private var _roll:Boolean;
  15.       
  16.       public var _hit:MovieClip;
  17.       
  18.       public function UIButton()
  19.       {
  20.          super();
  21.          _hit.alpha = 0;
  22.          _hit.addEventListener(MouseEvent.CLICK,onHitClick);
  23.          _hit.addEventListener(MouseEvent.MOUSE_OVER,onHitOver);
  24.          _hit.addEventListener(MouseEvent.MOUSE_OUT,onHitOut);
  25.          addEventListener("enterFrame",onUIButtonEnterFrame);
  26.          buttonMode = true;
  27.       }
  28.       
  29.       private function onUIButtonEnterFrame(event:*) : *
  30.       {
  31.          if(_roll)
  32.          {
  33.             _hit.alpha += (1 - _hit.alpha) * 0.25;
  34.          }
  35.          else
  36.          {
  37.             _hit.alpha += (0 - _hit.alpha) * 0.25;
  38.          }
  39.       }
  40.       
  41.       private function onHitOver(event:*) : *
  42.       {
  43.          _roll = true;
  44.       }
  45.       
  46.       private function onHitOut(event:*) : *
  47.       {
  48.          _roll = false;
  49.       }
  50.       
  51.       protected function onHitClick(event:*) : *
  52.       {
  53.          dispatchEvent(new Event("CLICK"));
  54.       }
  55.    }
  56. }
  57.